/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ssm.changeunit.communicate;

import com.ssm.changeunit.ChangeUnitException;
import org.apache.log4j.Logger;
import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServer;
import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
import org.apache.xmlrpc.webserver.WebServer;

/**
 * XML RPC 서비스를 제공하기 위한 Server
 * 
 * @author 시리우스
 */
public class ChangeUnitServer {
    private static Logger log = Logger.getLogger(ChangeUnitServer.class);
    
    private static final int port = 8080;

    public static void main(String[] args) throws Exception {
        // 환경 변수 체크
        if( System.getenv("CHANGEUNIT_ROOT") == null )
            throw new ChangeUnitException("CHANGEUNIT_ROOT 환경 변수를 찾을수 없습니다.");

        if( System.getenv("CHANGEUNIT_USERID") == null )
            throw new ChangeUnitException("CHANGEUNIT_USERID 환경 변수를 찾을수 없습니다.");
        
        WebServer webServer = new WebServer(port);

        XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();

        PropertyHandlerMapping phm = new PropertyHandlerMapping();
        phm.addHandler("ChangeUnitRPC", com.ssm.changeunit.communicate.ChangeUnitRPC.class);

        xmlRpcServer.setHandlerMapping(phm);
        XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
        serverConfig.setEnabledForExtensions(true);
        serverConfig.setContentLengthOptional(false);
        webServer.start();
        
        log.info("서버가 시작 되었습니다.");
    }
}
